unit FFPS;

interface
uses
 Windows, FLogs, SysUtils;

type
  TCount = Record
		New : Int64;
		Last : Int64;
		Frame : Integer;
  	FPS : Integer;
    Elapsed : Integer;
	end;

var
  Count : TCount;

procedure InitFPS();
procedure OnUpdateFPS();

implementation

procedure InitFPS();
begin
  Count.Last := GetTickCount();
  Count.New := GetTickCount();
  Count.Elapsed := 0;
  Count.Frame := 0;
  Count.FPS := 0;
end;

procedure OnUpdateFPS();
begin                         
  Count.Elapsed := GetTickCount() - Count.New;
	Count.New := Count.Elapsed + Count.New;
	Inc(Count.Frame);

	if (Count.New - Count.Last) > 1000 then begin
		Count.FPS := Trunc(Count.Frame * 1000 / (Count.New - Count.Last));
  	Log(FloatToStr(Count.FPS));
		Count.Last := Count.New;
		Count.Frame := 0;
	end;
end;

end.
